﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Audio;

namespace CorporationWars
{
    [Serializable]
    public class UIACIIKey : UIZone
    {
        public bool KeyNeedsShift { get; set; }
        public Keys XNAKey { get; set; }
        public Color HoverColor { get; set; }
        public Color MouseDownColor { get; set; }

        public int KeySpace { get; set; }
        public int KeySize { get; set; }

        public int ShadowHeight { get; set; }
        public Color shadwoColor = new Color(0, 0, 0, .5f);
        protected Rectangle ShadowRect
        {
            get
            {
                if (Name != "spbr")
                    return new Rectangle((int)Position.X + KeySpace + KeySpace - ShadowHeight, (int)Position.Y + KeySpace + (KeySpace / 2) + ShadowHeight, KeySize / 2, KeySize / 2);
                else
                    return new Rectangle((int)Position.X + KeySpace + KeySpace - ShadowHeight, (int)Position.Y + KeySpace + (KeySpace / 2) + ShadowHeight, Width - KeySize, KeySize / 2);
            }
        }

        protected Rectangle KeyRectangle
        {
            get
            {
                if (Name != "spbr")
                    return new Rectangle((int)Position.X + KeySpace + KeySpace, (int)Position.Y + KeySpace + (KeySpace / 2), KeySize / 2, KeySize / 2);
                else
                    return new Rectangle((int)Position.X + KeySpace + KeySpace, (int)Position.Y + KeySpace + (KeySpace / 2), Width - KeySize, KeySize / 2);
            }
        }

        public string Key { get; set; }

        public UIACIIKey(Game1 game)
            : base(game)
        {
            OpacityTolerance = 0;
            TextureAsset = "Textures/halfshade";
            RenderToolTipTop = false;
            KeyNeedsShift = false;
            spokeTip = true; // dont say  the tool tip.
        }

        public override void Draw(GameTime gameTime)
        {
            if (!IsVisible)
                return;

            // Render key BG
            spriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/halfshade"), renderRectangle, Color.White);

            if (!IsMouseOver)
            {
                spriteBatch.Draw(Game.Content.Load<Texture2D>(Key), ShadowRect, shadwoColor);
                spriteBatch.Draw(Game.Content.Load<Texture2D>(Key), KeyRectangle, Color);
            }
            else
            {
                if (!IsMouseDown)
                {
                    spriteBatch.Draw(Game.Content.Load<Texture2D>(Key), ShadowRect, shadwoColor);
                    spriteBatch.Draw(Game.Content.Load<Texture2D>(Key), KeyRectangle, HoverColor);
                    DrawToolTip(gameTime);
                }
                else
                    spriteBatch.Draw(Game.Content.Load<Texture2D>(Key), KeyRectangle, MouseDownColor);
            }
        }
    }
}
